'''
@文件    :views.py
@说明    :
@时间    :2020/04/04 21:53:29
@作者    :didiplus
@版本    :1.0
'''

from .__init__ import *
from flask import Blueprint,make_response,jsonify,json,request
dj = Blueprint('dj',__name__,url_prefix='/api/dj')

 # 电台banner
@dj.route('/banner',methods=['POST','GET'])
def banner():
     data = Send().POST("weapi/djradio/banner/get", {"os": "pc"})
     return make_response(jsonify(json.loads(data.text)),403)

# 热门电台
@dj.route('/hot',methods=['POST','GET'])
def hot():
    query = request_query(request, ["limit", {"limit": 30}], [
                          "offset", {"offset": 0}])
    data = Send(query).POST("weapi/djradio/hot/v1")
    return make_response(jsonify(json.loads(data.text)),403)


# 类别热门电台
@dj.route('/hot/radio',methods=['POST','GET'])
def hot_radio():
    query = request_query(request,
                          ["cid", "cateId"],
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}],)
    data = Send(query).POST("weapi/djradio/hot")
    return make_response(jsonify(json.loads(data.text)),403)


# 电台详情
@dj.route('/detail',methods=['POST','GET'])
def detail():
    query = request_query(request, ["rid", "id"])
    data = Send(query).POST("weapi/djradio/get")
    return make_response(jsonify(json.loads(data.text)),403)


# 付费精品
@dj.route('/paly',methods=['POST','GET'])
def pay():
    query = request_query(request, ["limit", {"limit": 100}])
    data = Send(query).POST("weapi/djradio/toplist/pay")
    return make_response(jsonify(json.loads(data.text)),403)

# 电台节目
@dj.route('/program',methods=['POST','GET'])
def program():
    query = request_query(request,
                          ["rid", "radioId"],
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}],
                          "asc")
    data = Send(query).POST("weapi/dj/program/byradio")
    return make_response(jsonify(json.loads(data.text)),403)

# 节目详情
@dj.route('/program/detail',methods=['POST','GET'])
def program_detail():
    
    query = request_query(request, "id")
    data = Send(query).POST("weapi/dj/program/detail")
    return make_response(jsonify(json.loads(data.text)),403)


# 节目榜
@dj.route('/program/toplist',methods=['POST','GET'])
def program_toplist():
    query = request_query(request, ["limit", {"limit": 100}])
    data = Send(query).POST("weapi/program/toplist/v1")
    return make_response(jsonify(json.loads(data.text)),403)

# 节目24小时榜
@dj.route('/program/toplist/hours',methods=['POST','GET'])
def program_toplist_hours():
    query = request_query(request, ["limit", {"limit": 100}])
    data = Send(query).POST("weapi/djprogram/toplist/hours")
    return make_response(jsonify(json.loads(data.text)),403)

# 24小时主播榜
@dj.route('/program/toplist/hours',methods=['POST','GET'])
def streamer_hours():
    query = request_query(request, ["limit", {"limit": 100}])
    data = Send(query).POST("weapi/dj/toplist/hours")
    return make_response(jsonify(json.loads(data.text)),403)

 # 主播新人榜
@dj.route('/streamer/newcomer',methods=['POST','GET'])
def streamer_newcomer():
    query = request_query(request, ["limit", {"limit": 100}])
    data = Send(query).POST("weapi/dj/toplist/newcomer")
    return make_response(jsonify(json.loads(data.text)),403)


# 最热主播榜
@dj.route('/streamer/hot',methods=['POST','GET'])
def streamer_hot():
    
    query = request_query(request, ["limit", {"limit": 100}])
    data = Send(query).POST("weapi/dj/toplist/popular")
    return make_response(jsonify(json.loads(data.text)),403)

# 新晋电台榜/热门电台榜
@dj.route('/toplist',methods=['POST','GET'])
def toplist():
    query = request_query(request, ["limit", {"limit": 100}], [
                          "offset", {"offset": 0}], ["type", {"type": 0}])
    data = Send(query).POST("weapi/djradio/toplist")
    return make_response(jsonify(json.loads(data.text)),403)

# 电台分类
@dj.route('/catelist',methods=['POST','GET'])
def catelist():
    
    data = Send().POST("weapi/djradio/category/get")
    return make_response(jsonify(json.loads(data.text)),403)

# 精选电台
@dj.route('/recommend',methods=['POST','GET'])
def recommend():
    data = Send().POST("weapi/djradio/recommend/v1")
    return make_response(jsonify(json.loads(data.text)),403)

# 分类推荐
@dj.route('/recommend/type',methods=['POST','GET'])
def recommend_type():
    query = request_query(request, ["cid", "cateId"])
    data = Send(query).POST("weapi/djradio/recommend")
    return make_response(jsonify(json.loads(data.text)),403)


# 推荐类型
@dj.route('/category/recommend',methods=['POST','GET'])
def category_recommend():
    data = Send().POST("weapi/djradio/home/category/recommend")
    return make_response(jsonify(json.loads(data.text)),403)

# 非热门类型
@dj.route('/category/excludehot',methods=['POST','GET'])
def category_excludehot():
    data = Send().POST("weapi/djradio/category/excludehot")
    return make_response(jsonify(json.loads(data.text)),403)

# 订阅
@dj.route('/sub',methods=['POST','GET'])
def sub():
    query = request_query(request, ["rid", "id"], ["type", {"type": 1}])
    type = "sub" if query.pop("type") == "1" else "unsub"
    data = Send(query).POST("weapi/djradio/" + type)
    return make_response(jsonify(json.loads(data.text)),403)

# 订阅列表
@dj.route('/sublist',methods=['POST','GET'])
def sublist():
    
    query = request_query(request,
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    query["total"] = True
    data = Send(query).POST("weapi/djradio/get/subed")
    return make_response(jsonify(json.loads(data.text)),403)

# 付费精选
@dj.route('/paygift',methods=['POST','GET'])
def paygift():
    query = request_query(request,
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    data = Send(query).POST("weapi/djradio/home/paygift/list?_nmclfl=1")
    return make_response(jsonify(json.loads(data.text)),403)

# 今日优选
@dj.route('/today',methods=['POST','GET'])
def today():
    query = request_query(request, ["page", {"page": 0}])
    data = Send(query).POST("weapi/djradio/home/today/perfered")
    return make_response(jsonify(json.loads(data.text)),403)

# 推荐电台
@dj.route('/djprogram',methods=['POST','GET'])
def djprogram():
    data = Send().POST("weapi/personalized/djprogram")
    return make_response(jsonify(json.loads(data.text)),403)


# 推荐节目
@dj.route('/program/recommend',methods=['POST','GET'])
def program_recommend():
    
    query = request_query(request, ["limit", {"limit": 10}],
                          ["offset", {"offset": 0}])
    data = Send(query).POST("weapi/program/recommend/v1")
    return make_response(jsonify(json.loads(data.text)),403)
